// state.cpp

#include "State.h"

State::State(){
}

void State::saveState(std::vector<Task> taskList){
	_prevStates.push(_currState);
	_currState = taskList;
	clearRedo();
}

void State::clearRedo(){
	while (!_nextStates.empty()){
		_nextStates.pop();
	}
}

bool State::undo(std::vector<Task> &taskList){
	if(_prevStates.empty()){
		return false;
	}
	
	_nextStates.push(_currState);
	_currState = _prevStates.top();
	_prevStates.pop();

	taskList = _currState;
	return true;
}

bool State::redo(std::vector<Task> &taskList){
	if(_nextStates.empty()){
		return false;
	}
	
	_prevStates.push(_currState);
	_currState = _nextStates.top();
	_nextStates.pop();

	taskList = _currState;
	return true;
}